/*
* @Author: mark
* @Date:   2016-09-27 17:33:45
* @Last Modified by:   mark
* @Last Modified time: 2017-01-16 12:38:26
*/
import api from '../config/api';

function request(path, data = {}, method = "GET") {
  const token = wx.getStorageSync('token');
  return new Promise((resolve, reject) => {
    wx.request({
      url: api.BaseUrl + path,
      method: method,
      data: Object.assign({}, data),
      header: {
        'Content-Type': 'application/json',
        'Authorization': token ? `Bearer ${token}` : null // 登录令牌
      },
      success: res => {
        const data = res.data;
        if (data.resCode !== 0) { // 返回码不为0，表示请求异常
          reject(data);
          return;
        }
        resolve(data);
      },
      fail: reject
    })
  });
}

// result : function (params) {

//     var _this = this;

//     return _this.fetchApi(params).then( res => res)

// }



export default request;
